package fr.sharpe.app.earthvisualizationdatamodel;

import java.awt.Color;
import java.io.Serializable;
import java.util.ArrayList;

import gov.nasa.worldwind.avlist.AVListImpl;
import gov.nasa.worldwind.geom.LatLon;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.render.Polyline;

public class Line extends Surface implements Serializable{

	private Line line = null;
	private String id;
	private ArrayList<PositionPoint> path;
	private Color color;
	private double opacity;
	private double width;
	private Data data;
	
	public Line(String id,ArrayList<PositionPoint> path,double width, double opacity,Color color, Data data)
	{
		this.id = id;
		this.path = path;
		this.setData(data);
		this.width = width;
		this.opacity = opacity;
		this.color = color;
	}
	
	@Override
	public AVListImpl getShape()
	{
		Polyline line = new Polyline();
		line.setPositions(getListLatLon(path));
		line.setFollowTerrain(true);
		line.setColor(color);
		line.setLineWidth(width);
		line.setOffset(opacity);
		return line;
	}

	@Override
	public String getId() {
		return this.id;
	}
	
	public ArrayList<Position> getListLatLon(ArrayList<PositionPoint> path)
	{
		ArrayList<Position> result = new ArrayList<Position>();
		for(PositionPoint p:path)
		{
			result.add(new Position(LatLon.fromDegrees(p.getLatitude(), p.getLongitude()),0));
		}
		return result;
	}

	public void setData(Data data) {
		this.data = data;
	}

	public Data getData() {
		return data;
	}

	public Line getLine() {
		return line;
	}

	public void setLine(Line line) {
		this.line = line;
	}

	public ArrayList<PositionPoint> getPath() {
		return path;
	}

	public void setPath(ArrayList<PositionPoint> path) {
		this.path = path;
	}

	public Color getColor() {
		return color;
	}

	public void setColor(Color color) {
		this.color = color;
	}

	public double getOpacity() {
		return opacity;
	}

	public void setOpacity(double opacity) {
		this.opacity = opacity;
	}

	public double getWidth() {
		return width;
	}

	public void setWidth(double width) {
		this.width = width;
	}

	public void setId(String id) {
		this.id = id;
	}
}
